package com.cdut.logistics.model.dao.datacentre;

import java.util.Date;
import com.cdut.logistics.model.entity.BaseModel.BaseMajor;
import com.jfinal.plugin.activerecord.Db;

/**  
 * @ClassName: major
 * @Description: 操作数据库 
 * @author wxt.xia
 * @date 2018年1月26日 上午9:13:52    
 */
public class Major extends BaseMajor<Major>{
	private static final long serialVersionUID = 1L;
	public String baseSql = " and is_use = 1";
	public String sql1 = "SELECT "+
			"major.id,"+
			"major.`name`,"+
			"school.name as 's_name' "+
			"FROM major join school "+
			"ON major.school_id=school.id AND school.is_use =1 "+
			"AND major.is_use = 1 AND major.name like ?";
	public String sql4 = "SELECT * from major where school_id = ? "+baseSql;
	public String sql2 = "UPDATE major set name =?, updated=? where id =?"+ baseSql;
	public String sql3 = "UPDATE major set is_use =?, updated=? where id =?"+ baseSql;
	/**  
	 * @Title: save  
	 * @Description: 新增专业
	 * @author wxt.xia
	 * @param major
	 * @throws  
	 */
	public void save(Major major) {
		major.set("created", new Date());
		major.set("updated", new Date());
		major.set("is_use", 1);
		major.set("active", 1);
		major.save();
	}

	/**  
	 * @Title: update  
	 * @Description: 修改专业
	 * @author wxt.xia
	 * @param dept
	 * @throws  
	 */
	public void update(Major major) {
		major.set("updated", new Date());
		Db.update(sql2,major.get("name"),major.get("updated"),major.get("id"));
	}

	/**  
	 * @Title: remove  
	 * @Description: 删除专业
	 * @author wxt.xia
	 * @param id
	 * @throws  
	 */
	public void remove(int id) {
		Db.update(sql3,0,new Date(),id);
	}
}
